package com.hzw.saas.web.hbox.enums;

import java.util.Objects;

import com.hzw.saas.common.config.exception.DefaultSaasException;
import cn.hutool.core.lang.Assert;
import org.springframework.http.HttpStatus;

/**
 * @author zzl
 * @since 02/26/2021
 */
public enum HBoxSpace {

    USER_SPACE(10, "个人空间"),
    SHARE_SPACE(20, "共享空间"),
    ;

    private final Integer code;
    private final String text;

    HBoxSpace(Integer code, String text) {
        this.code = code;
        this.text = text;
    }

    public Integer code() {
        return code;
    }

    public String text() {
        return text;
    }

    public static String text(Integer code) {
        for (HBoxSpace value : HBoxSpace.values()) {
            if (Objects.equals(value.code, code)) {
                return value.text;
            }
        }
        return null;
    }

    public static HBoxSpace instance(Integer code) {
        for (HBoxSpace value : HBoxSpace.values()) {
            if (Objects.equals(value.code, code)) {
                return value;
            }
        }
        return null;
    }

    public static HBoxSpace assertInstance(Integer code) {
        HBoxSpace instance = instance(code);
        Assert.notNull(instance, "空间编号异常: {}", code);
        return instance;
    }

}
